<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="/admin/_layouts/default">
<head>
    <title>修改菜单信息</title>
</head>
<body>
<div layout:fragment="content">
    <!-- 内容区域 -->
    <section class="content">
        <!-- Small boxes (Stat box) -->
        <div class="row">
            <div class="col-xs-12 i-navbar">
                <a class="btn btn-primary" th:href="@{/admin/system/menu/index.html}" data-pjax><i
                        class="fa fa-arrow-left"></i> 返回
                </a>
            </div>
            <div class="col-xs-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">修改菜单信息</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form id="js-form"
                          th:action="@{/admin/system/menu/update}"
                          method="POST">
                        <input type="hidden" name="id"
                               th:value="${permission?.id}">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="parent">上级菜单</label>
                                <input type="text" class="form-control" id="parent"
                                       placeholder="不选择默认为顶级菜单"
                                       th:value="${parent?.name}?:'顶级菜单'"
                                       disabled="disabled">
                            </div>
                            <div class="form-group">
                                <label for="name">菜单名称 <span class="i-label label-warning">必填</span></label>
                                <input class="form-control" id="name" name="name"
                                       placeholder="请输入菜单名称"
                                       required
                                       th:value="${permission?.name}"
                                       type="text">
                            </div>
                            <div class="form-group">
                                <label for="type">菜单类型 <span class="i-label label-warning">必填</span></label>
                                <select class="form-control" id="type" name="type">
                                    <option value="0" th:selected="${permission?.type==0}">菜单</option>
                                    <option value="1" th:selected="${permission?.type==1}">数据</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="permission">菜单标识 <span class="i-label label-warning">必填</span></label>
                                <input class="form-control" id="permission" name="permission"
                                       placeholder="请输入权限标识"
                                       required
                                       th:value="${permission?.permission}"
                                       type="text">
                                <p class="help-block">例如：sys.manager.unit</p>
                            </div>

                            <div id="divId" th:style="${permission?.type==0?'':'display:none'}">
                                <div class="form-group">
                                    <label for="url">URL</label>
                                    <input class="form-control" id="url" name="url"
                                           placeholder="请输入URL"
                                           th:value="${permission?.url}"
                                           type="text">
                                </div>
                                <div class="form-group">
                                    <label for="target">Target</label>
                                    <input class="form-control" id="target" name="target"
                                           placeholder="请输入target"
                                           th:value="${permission?.target}"
                                           type="text">
                                </div>
                                <div class="form-group">
                                    <label for="icon">图标</label>
                                    <input class="form-control" id="icon" name="icon"
                                           placeholder="请输入图标"
                                           th:value="${permission?.icon}"
                                           type="text">
                                    <p class="help-block">图标预览: <i id="js-show-icon"></i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" name="available"
                                               th:checked="${permission?.available}"> 是否启用
                                    </label>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-body -->

                        <div class="box-footer">
                            <button class="btn btn-primary" type="submit">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- /.row -->
    </section>
    <!-- /内容区域 -->
    <script>
        $(function () {
            $('#js-form').ajaxForm({
                dataType: 'json',
                beforeSubmit: function (arr, form, option) {
                    form.find("button:submit").attr('disable', true);
                },
                success: function (data, statusText, xhr, form) {
                    if (data.code === 200) {
                        layer.msg(data.message, {icon: 1});
                    } else {
                        layer.msg(data.message, {icon: 2});
                    }
                    form.find("button:submit").attr('disable', false);
                }
            });
            // 图标实时预览
            $('#icon').on('keyup', function () {
                $('#js-show-icon').attr('class', $(this).val());
            });
            $("#type").on("change", function () {
                if ($(this).val() === '0') {
                    $("#divId").show();
                } else {
                    $("#url").val("");
                    $("#target").val("");
                    $("#icon").val("");
                    $("#divId").hide();
                }
            });
        });
    </script>
</div>
</body>
</html>
